package com.liyujie.networkrequest.mobile.event;

import android.os.Bundle;
import android.os.Parcelable;

import java.io.Serializable;

public class MessageEvent {
    private static final String KEY_INT = "key_int";
    private static final String KEY_STRING = "key_string";
    private static final String KEY_BOOL = "key_bool";
    private static final String KEY_SERIALIZABLE = "key_serializable";
    private static final String KEY_PARCELABLE = "key_parcelable";



    private MessageType type;
    private Bundle bundle;

    public MessageEvent(MessageType type) {
        this.type = type;
        this.bundle = new Bundle();
    }

    public MessageEvent put(int value) {
        bundle.putInt(KEY_INT, value);
        return this;
    }

    public MessageEvent put(String value) {
        bundle.putString(KEY_STRING, value);
        return this;
    }

    public MessageEvent put(boolean value) {
        bundle.putBoolean(KEY_BOOL, value);
        return this;
    }

    public MessageEvent put(long value) {
        bundle.putLong(KEY_BOOL, value);
        return this;
    }

    public MessageEvent put(Serializable value) {
        bundle.putSerializable(KEY_SERIALIZABLE, value);
        return this;
    }

    public MessageEvent put(Parcelable value) {
        bundle.putParcelable(KEY_PARCELABLE, value);
        return this;
    }

    public MessageEvent put(String key, int value) {
        bundle.putInt(key, value);
        return this;
    }

    public MessageEvent put(String key, String value) {
        bundle.putString(key, value);
        return this;
    }

    public MessageEvent put(String key, boolean value) {
        bundle.putBoolean(key, value);
        return this;
    }

    public MessageEvent put(String key, Serializable value) {
        bundle.putSerializable(key, value);
        return this;
    }

    public MessageEvent put(String key, Parcelable value) {
        bundle.putParcelable(key, value);
        return this;
    }

    public int getInt() {
        return bundle.getInt(KEY_INT);
    }

    public String getString() {
        return bundle.getString(KEY_STRING);
    }

    public boolean getBoolean() {
        return bundle.getBoolean(KEY_BOOL);
    }


    public long getLong() {
        return bundle.getLong(KEY_BOOL);
    }


    public <T extends Serializable> T getSerializable() {
        return (T) bundle.getSerializable(KEY_SERIALIZABLE);
    }

    public <T extends Parcelable> T getParcelable() {
        return bundle.getParcelable(KEY_PARCELABLE);
    }

    public int getInt(String key) {
        return bundle.getInt(key);
    }

    public String getString(String key) {
        return bundle.getString(key);
    }

    public boolean getBoolean(String key) {
        return bundle.getBoolean(key);
    }

    public long getLong(String key) {
        return bundle.getLong(key);
    }


    public <T extends Serializable> T getSerializable(String key) {
        return (T) bundle.getSerializable(key);
    }

    public <T extends Parcelable> T getParcelable(String key) {
        return bundle.getParcelable(key);
    }

    public MessageType getType() {
        return type;
    }

    public void setType(MessageType type) {
        this.type = type;
    }
}


